/********************************************************************************
* Analysis of Patient Satisfaction Survey 							
*
* 	Created: 30 October 2018
* 	Last updated: 4 November 2018
*
*		
*
*******************************************************************************/

clear all
set more off
program drop _all

/******************************************
		SELECT Change global serverpath for different users
******************************************/

global serverpath  "xxx"

use "$serverpath/patientsatis_2018-10-30.dta", clear


/******************************************************************************						
		1. Sample characteristics
******************************************************************************/

gen age_grp = . 
replace age_grp = 1 if AGE>=17 & AGE <20 & AGE !=.
replace age_grp = 2 if AGE>=20 & AGE <25 & AGE !=.
replace age_grp = 3 if AGE>=25 & AGE <30 & AGE !=.
replace age_grp = 4 if AGE>=30 & AGE <35 & AGE !=.
replace age_grp = 5 if AGE>=35 & AGE <40 & AGE !=.
replace age_grp = 6 if AGE>=40 & AGE !=.


gen married = . 
replace married = 1 if MARITALSTATUS==1
replace married = 0 if MARITALSTATUS>1 & MARITALSTATUS!=.

gen givenbirthnum = HOWMANYDELIVERIES 
replace givenbirthnum = 4 if HOWMANYDELIVERIES >4 & HOWMANYDELIVERIES!=. // "4 or more"


table1, vars(AGE contn \ age_grp cat \ givenbirthnum cat \ married cat\ EDUCATION cat \ CURRENTOCCUPATION cat \  BMONTHLYEXPENDITURE cat) format(%2.1f) saving("$serverpath/table1.xls", replace)


/******************************************************************************						
		2. Overall quality of healthcare
******************************************************************************/
// Overall quality
gen goodqual = . 
replace goodqual = 1 if RATEHEALTHCARE == 1 | RATEHEALTHCARE == 2
replace goodqual = 0 if RATEHEALTHCARE == 3 | RATEHEALTHCARE == 4 | RATEHEALTHCARE == 5

svyset FACILITYNAME
svy: mean goodqual


/******************************************************************************						
		3. Time to attend PMTCT
******************************************************************************/

// Time to travel to clinic
gen time30to60 = . 
replace time30to60 = 1 if TIMETOCLINIC == 3
replace time30to60 = 0 if TIMETOCLINIC == 1 | TIMETOCLINIC == 2  | TIMETOCLINIC == 4 
svy: mean time30to60

gen timeover60 = . 
replace timeover60 = 1 if TIMETOCLINIC == 4
replace timeover60 = 0 if TIMETOCLINIC == 1 | TIMETOCLINIC == 2  | TIMETOCLINIC == 3 
svy: mean timeover60


// Time spent at facility
gen timeatcliniconehr = .
replace timeatcliniconehr = 0 if TIMESPENTLASTVISIT<1 
replace timeatcliniconehr = 1 if TIMESPENTLASTVISIT>=1 & TIMESPENTLASTVISIT !=.

svy: mean timeatcliniconehr


gen timeatclinic3hr = .
replace timeatclinic3hr = 0 if TIMESPENTLASTVISIT<3 
replace timeatclinic3hr = 1 if TIMESPENTLASTVISIT>=3 & TIMESPENTLASTVISIT !=.

svy: mean timeatclinic3hr

/******************************************************************************						
		4. Cost of attending PMTCT
******************************************************************************/

replace TRANSPORTCOST = 0 if TRANSPORTCOST ==.
replace TRANSPORTCOST = TRANSPORTCOST*2 // transport is one way
replace CHILDCARECOST = 0 if CHILDCARECOST ==.
replace FOODCOST = 0 if FOODCOST ==.
replace PHONECOST = 0 if PHONECOST ==.
replace OTHERCOSTS = 0 if OTHERCOSTS ==.
replace CHOWMUCHMONEYLOST = 0 if CHOWMUCHMONEYLOST ==.


gen totalcost = .
replace totalcost = TRANSPORTCOST + CHILDCARECOST + FOODCOST + PHONECOST + OTHERCOSTS + CHOWMUCHMONEYLOST

mean totalcost
dis 4833.785/602.02 // convert mean for total to PPP

mean CHOWMUCHMONEYLOST
dis 2078.995/602.02

mean TRANSPORTCOST

mean FOODCOST
dis 458.9076 / 602.02

mean CHILDCARECOST
dis 108.2353 / 602.02

mean PHONECOST
dis 80.42017 / 602.02

mean OTHERCOSTS
dis  56.80672 / 602.02 // 0.09

gen totalcostppp = totalcost/602.02
svy: mean totalcostppp

